package rule

import (
	"crypto/sha256"
	"fmt"

	"admin_template/bff/admin/internal/pkg/middleware"
	servicesSystem "admin_template/bff/admin/internal/service/system"
	hertzMiddleware "gitee.com/byx_darwin/go-tools/hertz/middleware"
	"github.com/cloudwego/hertz/pkg/app/middlewares/server/recovery"
	"github.com/cloudwego/hertz/pkg/app/server"
)

func Register(server *server.Hertz, api *servicesSystem.RuleService) {
	apiGroup := server.Group(fmt.Sprintf("/%s/system/rule", api.Config.ServerOption.Registry.Version))
	apiGroup.Use(recovery.Recovery(recovery.WithRecoveryHandler(api.RecoveryHandler)))
	apiGroup.Use(hertzMiddleware.Auth(api, sha256.New))
	apiGroup.Use(middleware.JWTAuth(api.Config))
	apiGroup.Use(middleware.EnforcerHandler(api))

	{
		apiGroup.POST("", api.Add)
		apiGroup.PUT("", api.UpdateInfo)
		apiGroup.DELETE("", api.Del)
		apiGroup.PUT("/state", api.UpdateState)
		apiGroup.GET("", api.List)
		apiGroup.GET("/all", api.All)
	}
}
